{{ .dataGrid }}

<script>

    var database_backup_list_datagrid_toolbar = [
        {
            text: '刷新', iconCls: 'icons-arrow-arrow_refresh', handler: function () {
                $('#database_backup_list_datagrid').datagrid('reload');
            }
        },
    ];


    function backupListOpFormatter(name) {
        var btn = [];
        btn.push("<a href=\"javascript:;\" onclick=\"downloadBackupList('" + name + "')\" title='仅登录后端后可下载'>下载</a>");
        btn.push("<a href=\"javascript:;\" onclick=\"deleteBackupList('" + name + "')\">删除</a>");
        return btn.join(' | ');
    }

    function downloadBackupList(name) {
        $.post("/b/database/backup-download", {name: name}, function (res) {
            if (res.errcode) {
                $.messager.alert('提示信息', res.errmsg, 'error');
            } else {
                var a = document.createElement('a');
                a.href = res.errmsg;
                a.target = '_blank';
                a.id = 'download';
                document.body.appendChild(a);
                var alink = document.getElementById('download');
                alink.click();
                alink.parentNode.removeChild(a);
            }
        });
    }

    function deleteBackupList(name) {
        $.messager.confirm("删除提醒", "确定要删除备份文件吗？", function (result) {
            if (!result) return false;
            $.post("/b/database/backup-delete", {name: name}, function (res) {
                if (res.errcode) {
                    $.messager.alert('提示信息', res.errmsg, 'error');
                } else {
                    $.messager.alert('提示信息', res.errmsg, 'info');
                    $('#database_backup_list_datagrid').datagrid('reload');
                }
            });
        })

    }
</script>
